<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php
	function getHFBSetList()
	{
		$i=0;
		$result = mysql_query("SELECT id, name FROM ".DB_PERFIX."hfb_sets;");
		while($row = mysql_fetch_array($result))
		{
			$item[$i]['id'] = $row['id'];
			$item[$i]['name'] = $row['name'];
			$i++;
		}
		return $item;
	}
	
	function getModComSets()
	{
		$i=0;
		$result = mysql_query("SELECT * FROM ".DB_PERFIX."admin_modcom_sets ORDER BY id ASC;");
		while($row = mysql_fetch_array($result))
		{
			$item[$i]['id'] = $row['id'];
			$item[$i]['title'] = $row['title'];
			$i++;
		}
		return $item;
	}	
	
class Commander extends ObjectController
{
	public $SiteId;
	public $ThemeId;
	public $Con;
	public $PostAction;
	public $Words;
	public $UserLevels;
	public $List;
	public $Edit;
	public $Editor;
	
	public function Commander()
	{
		self::setSiteId(SITE_ID); 
		if($_REQUEST['con'] > 0)
		{ self::setCon($_REQUEST['con']); }
		else
		{ self::setCon(DEFCON); }
		self::loadPostAction();
		self::loadList();
		self::loadEdit();
		self::loadEditor();
	}
	
	public function getSiteId() { return intval($this->SiteId); }
	public function getCon() { return intval($this->Con); }
	public function getPostAction() { return $this->PostAction; }
	public function getWords() { return $this->Words; }
	public function getUserLevels() 
	{
		if($this->UserLevels)
		{ return $this->UserLevels; }
		else
		{
			self::loadUserLevels();
			return $this->UserLevels;
		}
	}
	
	public function setSiteId($val) { $this->SiteId=intval($val); }
	public function setCon($val) { $this->Con=intval($val); }
	public function setPostAction($val) { $this->PostAction=$val; }
	public function setWords($val) { $this->Words=$val; }
	public function setUserLevels($val) { $this->UserLevels=$val; }
	
	function getWord($value, $words = '')
	{
		if($words)
		{
			if(isset($words[$value]))
			{ return self::formatText($words[$value]); }
			else
			{ return $value; }
		}
		else
		{
			if(isset($this->Words[$value]))
			{ return self::formatText($this->Words[$value]); }
			else
			{ return $value; }
		}
	}

	function getWordExplicit($value, $words = '')
	{
		if($words)
		{
			if(isset($words[$value]))
			{ return self::formatText($words[$value]); }
			else
			{ return ''; }
		}
		else
		{
			if(isset($this->Words[$value]))
			{ return self::formatText($this->Words[$value]); }
			else
			{ return ''; }
		}
	}
	
	function getInpPar($type, $name, $value='', $maxlength=0, $size=0, $id='', $class='')
	{
		$output = '';
		
		if($type != '')
		{ $output .= ' type="'.$type.'" '; } 
		
		if($name != '')
		{ $output .= ' name="'.$name.'" '; }
		
		if($value != '')
		{ $output .= ' value="'.$value.'" '; } 
		
		if($maxlength > 0)
		{ $output .= ' maxlength="'.$maxlength.'" '; }
		
		if($size > 0)
		{ $output .= ' size="'.$size.'" '; }
		
		if($id != '')
		{ $output .= ' id="'.$id.'" '; }
		return $output;
	}
	
	function loadPostAction()
	{
		if($_POST['action'] != '')
		{ self::setPostAction($_POST['action']); }
		else if($_POST['oper'] != '')
		{ self::setPostAction($_POST['oper']); }
	}
	
	function loadList()
	{
		if($_REQUEST['list'] != '')
		{ self::setList($_REQUEST['list']); }
	}
	
	function loadEdit()
	{
		if($_REQUEST['edit'] != '')
		{ self::setEdit($_REQUEST['edit']); }
	}
	
	function loadEditor()
	{
		if($_REQUEST['editor'] != '')
		{ self::setEditor($_REQUEST['editor']); }
	}
	
	function getFormAction($format='')
	{
		$action = '?con='.$this->Con;
		
		if($_GET['list'] != '')
		{ $action .= '&amp;list='.$_GET['list'];}
		
		if($_GET['edit'] != '')
		{ $action .= '&amp;edit='.$_GET['edit'];}
		
		if($_GET['cat'] > 0)
		{ $action .= '&amp;cat='.$_GET['cat'];}
		
		if($_GET['grp'] > 0)
		{ $action .= '&amp;grp='.$_GET['grp'];}
		
		if($_GET['atr'] > 0)
		{ $action .= '&amp;atr='.$_GET['atr'];}
		
		if($_GET['attribute'] > 0)
		{ $action .= '&amp;attribute='.$_GET['attribute'];}
		
		if($_GET['item'] > 0)
		{ $action .= '&amp;item='.$_GET['item'];}
		
		if($_GET['sec'] > 0)
		{ $action .= '&amp;sec='.$_GET['sec'];}
		
		if($_GET['provider'] > 0)
		{ $action .= '&amp;provider='.$_GET['provider'];}
		
		if($_GET['brand'] > 0)
		{ $action .= '&amp;brand='.$_GET['brand'];}
		
		if($_GET['adbrand'] > 0)
		{ $action .= '&amp;adbrand='.$_GET['adbrand'];}
		
		if($_GET['exe'] > 0)
		{ $action .= '&amp;exe='.$_GET['exe'];}
		
		if($_GET['shipping'] > 0)
		{ $action .= '&amp;shipping='.$_GET['shipping'];}
		
		if($_GET['status'] > 0)
		{ $action .= '&amp;status='.$_GET['status'];}
		
		if($_GET['ship'] > 0)
		{ $action .= '&amp;ship='.$_GET['ship'];}
		
		if($_GET['s'] > 0)
		{ $action .= '&amp;s='.$_GET['s'];}
		
		if($_GET['m'] > 0)
		{ $action .= '&amp;m='.$_GET['m'];}
		
		if($_GET['p'] > 0)
		{ $action .= '&amp;p='.$_GET['p'];}
		
		if($_REQUEST['v'] > 0)
		{ $action .= '&amp;v='.$_REQUEST['v'];}
		
		if($_GET['i'] > 0)
		{ $action .= '&amp;i='.$_GET['i'];}
		
		if($_GET['r'] > 0)
		{ $action .= '&amp;r='.$_GET['r'];}
		
		if($_GET['stat'] > 0)
		{ $action .= '&amp;stat='.$_GET['stat']; }
		
		if($_GET['type'] != '')
		{ $action .= '&amp;type='.$_GET['type']; }
		
		if($_GET['active'] != '')
		{ $action .= '&amp;active='.$_GET['active']; }
		
		if($_GET['archived'] != '')
		{ $action .= '&amp;archived='.$_GET['archived']; }
		
		if($_GET['deleted'] != '')
		{ $action .= '&amp;deleted='.$_GET['deleted']; }
		
		
		if($_GET['typeId'] != '')
		{ $action .= '&amp;typeId='.$_GET['typeId']; }
		if($_GET['catId'] != '')
		{ $action .= '&amp;catId='.$_GET['catId']; }
		
		if($_GET['editor'] != '')
		{ $action .= '&amp;editor='.$_GET['editor']; }
		
		if($_GET['ad'] != '')
		{ $action .= '&amp;ad='.$_GET['ad']; }
		
		if(intval($_GET['user']) > 0)
		{ $action .= '&amp;user='.intval($_GET['user']); }
		
		if($_GET['object'] != '')
		{ $action .= '&amp;object='.$_GET['object']; }
		
		if($_REQUEST['report'] != '')
		{ $action .= '&amp;report='.$_REQUEST['report']; }
		
		if($_GET['form'] != '')
		{ $action .= '&amp;form='.$_GET['form']; }
		
		if($_GET['view'] != '')
		{ $action .= '&amp;view='.$_GET['view']; }
		
		if(intval($_GET['page']) > 0)
		{ $action .= '&amp;page='.intval($_GET['page']); }
		
		if($_GET['display'] != '')
		{ $action .= '&amp;display='.$_GET['display']; }
		
		if($_GET['ajax'] != '')
		{ $action .= '&amp;ajax='.$_GET['ajax']; }
		
		if($_REQUEST['q'] != '')
		{ $action .= '&amp;q='.$_REQUEST['q']; }
		
		if($_REQUEST['date_start'] != '')
		{ $action .= '&amp;date_start='.$_REQUEST['date_start']; }
		
		if($_REQUEST['date_end'] != '')
		{ $action .= '&amp;date_end='.$_REQUEST['date_end']; }
		
		if($_REQUEST['shipping-method'] != '')
		{ $action .= '&amp;shipping-method='.$_REQUEST['shipping-method']; }
		
		if($_GET['output_format'] != '')
		{ 
			$action .= '&amp;output_format='.$_GET['output_format']; 
			define('OUTPUT_FORMAT', $_GET['output_format']);
		}
		if(defined(AJAX_RUN) || ($format == 'ajax'))
		{ $action = str_replace('&amp;', '&', $action); }
		return $action;
	}

	function getActivationFields($item)
	{
		if($item)
		{
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'active_'.$item['active'].'_16.gif"';
			if($item['active'] == 0)
			{ $output .= ' alt="activate" onmousedown="document.getElementById(\'activate\').value='.$item['id'].';"'; }
			else
			{ $output .= ' alt="deactivate" onmousedown="document.getElementById(\'deactivate\').value='.$item['id'].';"'; }
			$output .= ' onmouseup="edit_form.submit();" />';
			return $output;
		}
	}
	
	function getActivationFieldsObject($object)
	{
		if($object)
		{
			$item['active'] = 0;
			if($object->getActive())
			{ $item['active'] = 1; }
			
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'active_'.$item['active'].'_16.gif"';
			if($item['active'] == 0)
			{ $output .= ' alt="'.ucfirst($this->Words['activate']).'" onmousedown="document.getElementById(\'activate\').value='.$object->getId().';"'; }
			else
			{ $output .= ' alt="'.ucfirst($this->Words['deactivate']).'" onmousedown="document.getElementById(\'deactivate\').value='.$object->getId().';"'; }
			$output .= ' onmouseup="edit_form.submit();" />';
			return $output;
		}
	}
	
	function getActivationFieldsObjectAjax($object)
	{
		if($object)
		{
			$item['active'] = 0;
			if($object->getActive())
			{ $item['active'] = 1; }
			
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'active_'.$item['active'].'_16.gif"';
			if($item['active'] == 0)
			{ $output .= ' alt="'.ucfirst($this->Words['activate']).'" onclick="itemActivate('.$object->getId().');"'; }
			else
			{ $output .= ' alt="'.ucfirst($this->Words['deactivate']).'" onclick="itemDeactivate('.$object->getId().');"'; }
			$output .= ' />';
			return $output;
		}
	}
	
	function getSortButtonAjax($button='up', $id=0)
	{
		if(($button != '') && ($id > 0))
		{
			switch ($button)
			{
				case 'up':
					$buttons[0]['image'] = 'arrow_up_16.gif';
					$buttons[0]['onclick'] = 'itemSortUp('.$id.');';
					$buttons[0]['title'] = ucfirst($this->Words['move_up']);
					break;
				case 'down':
					$buttons[0]['image'] = "arrow_down_16.gif";
					$buttons[0]['onclick'] = 'itemSortDown('.$id.');';
					$buttons[0]['title'] = ucfirst($this->Words['move_down']);
					break;
			}
			if($buttons)
			{ return self::getCommandButtons($buttons); }
		}
	}
	
	function getDefaultFields($item, $field='set_default')
	{
		if(is_object($item))
		{
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'active_'.$item->Default.'_16.gif"';
			if($item->Default == 0)
			{ $output .= ' alt="set as default" onmousedown="document.getElementById(\''.$field.'\').value='.$item->Id.';"'; }
			$output .= ' onmouseup="edit_form.submit();" />';
			return $output;
		}
		else if(is_array($item))
		{
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'active_'.$item['default'].'_16.gif"';
			if($item['default'] == 0)
			{ $output .= ' alt="set as default" onmousedown="document.getElementById(\''.$field.'\').value='.$item['id'].';"'; }
			$output .= ' onmouseup="edit_form.submit();" />';
			return $output;
		}
	}
	
	function getArchiveFieldsObject($object)
	{
		if($object)
		{
			$archived = 0;
			if($object->getArchived())
			{ $archived = 1; }
			
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'archived_'.$archived.'_16.gif"';
			if($archived == 0)
			{ $output .= ' alt="'.ucfirst(self::getWord('archive')).'" onmousedown="document.getElementById(\'archive\').value='.$object->getId().';"'; }
			else
			{ $output .= ' alt="'.ucfirst(self::getWord('unarchive')).'" onmousedown="document.getElementById(\'unarchive\').value='.$object->getId().';"'; }
			$output .= ' onmouseup="edit_form.submit();" />';
			return $output;
		}
	}
	function getArchiveFieldsObjectAjax($object)
	{
		if($object)
		{
			$archived = 0;
			if($object->getArchived())
			{ $archived = 1; }
			
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'archived_'.$archived.'_16.gif"';
			if($archived == 0)
			{ $output .= ' alt="'.ucfirst($this->Words['archive']).'" onclick="itemArchive('.$object->getId().');"'; }
			else
			{ $output .= ' alt="'.ucfirst($this->Words['unarchive']).'" onclick="itemUnArchive('.$object->getId().');"'; }
			$output .= ' />';
			return $output;
		}
	}
	
	function getTrueFields($item, $fieldtrue='true', $fieldfalse='true', $value, $trueval='1')
	{
		if($item)
		{
			$output = '<img class="command icon"';
			
			if($item[$value] == $trueval)
			{ 
				$output .= ' src="'.SYSICONS_URL.'active_1_16.gif"';
				$output .= ' alt="activate" onmousedown="document.getElementById(\''.$fieldfalse.'\').value='.$item['id'].';"'; 
			}
			else
			{ 
				$output .= ' src="'.SYSICONS_URL.'active_0_16.gif"';
				$output .= ' alt="deactivate" onmousedown="document.getElementById(\''.$fieldtrue.'\').value='.$item['id'].';"'; 
			}
			$output .= ' onmouseup="edit_form.submit();" />';
			return $output;
		}
	}
	
	function getClients()
	{
		$i=0;
		$result = mysql_query('SELECT * FROM '.DB_PERFIX.'admin_clients ORDER BY id ASC;');
		while($row = mysql_fetch_array($result))
		{
			$item[$i]['id'] = $row['id'];
			$item[$i]['name'] = $row['name'];
			$item[$i]['contact'] = $row['contact'];
			$item[$i]['email'] = $row['email'];
			$item[$i]['msn'] = $row['msn'];
			$item[$i]['skype'] = $row['skype'];
			$item[$i]['description'] = $row['description'];
			$i++;
		}
		return $item;
	}
	
	function getHFBSetList()
	{
		$i=0;
		$result = mysql_query("SELECT id, name FROM ".DB_PERFIX."hfb_sets;");
		while($row = mysql_fetch_array($result))
		{
			$item[$i]['id'] = $row['id'];
			$item[$i]['name'] = $row['name'];
			$i++;
		}
		return $item;
	}
	
	function getModComSets()
	{
		$i=0;
		$result = mysql_query("SELECT * FROM ".DB_PERFIX."admin_modcom_sets ORDER BY id ASC;");
		while($row = mysql_fetch_array($result))
		{
			$item[$i]['id'] = $row['id'];
			$item[$i]['title'] = $row['title'];
			$i++;
		}
		return $item;
	}

	public function formatPrice($price)
	{
		if($price > 0)
		{ 
			$price = str_ireplace(' ','',$price);
			$price = str_ireplace(',','.',$price);
			$price = number_format($price,2,'.','');
		}
		return $price;
	}

	public function formatAlias($txt)
	{
		if($txt != '')
		{
			$txt = self::formatText($txt);
			$txt = strtolower($txt);
			
			$searchMulti = array
			( 
				' ', 
				',', 
				'/' , 
				'\\' , 
				'\'' , 
				'&_' , 
				'&auml;' , 
				'&ouml;' , 
				'&szlig;' , 
				'&uuml;' , 
				'&aelig;' , 
				'&oslash;' , 
				'&aring;' , 
				'&eacute;', 
				'&egrave;',
				'&#262;',
				'&#263;',
				'&#268;',
				'&#269;'				
			);
			
			$replaceMulti 	= array
			(
				'_', 
				'_', 
				'_', 
				'_', 
				'_', 
				'and_' , 
				'ae' , 
				'oe' , 
				'sz' , 
				'ue' , 
				'ae' , 
				'o' , 
				'aa' , 
				'e', 
				'e',
				'c',
				'c',
				'c',
				'c'
			);
			
			$txt = str_replace($searchMulti, $replaceMulti, $txt);
		}
		
		return $txt; 
	}

	public function formatSearchIndex($txt = '')
	{
		if(isset($txt) && ($txt != ''))
		{ 
			$txt = trim(strtolower($txt));
			$txt = strip_tags($txt);
			$txt = str_replace("\t", "", $txt);
			$txt = str_replace("\n", "", $txt);
			$txt = str_replace("\r", "", $txt);
			$txt = str_replace("&nbsp;", "", $txt);
			$txt = str_replace(" ", ",", $txt);
			
			$words = split(",", $txt);
			$txt = '';
			if($words)
			{
				foreach($words as $word)
				{
					if(strlen($word) > 2)
					{ $index[$word] = $word; }
				}
			}
			if($index) 
			{
				foreach($index as $word)
				{ $txt .= trim(utf8_encode($word)).','; }
			}
			$txt = str_replace(",,", ",", $txt);
		}
		return $txt;
	}
	
	function stripNum($val)
	{
		$out = eregi_replace("([0-9]+)","",$val);
		return ($out);
	}
	
	function stripAlpha($val)
	{
		$out = eregi_replace("([A-Z]+)","",$val);
		return $out;
	}
	
	function stripSpace($val)
	{
		str_replace(' ','',$val);
		return $val;
	}
	
	function hasSpace($val)
	{
		if( ereg("[ 	]",$val) )
		{ return true; }
		else
		{ return false;	}
	}
	
	function isAllNum($val)
	{
		if((gettype($val)) == "integer")	
		{ return true; }
		return false;
	}
	
	function isEmail($email)
	{
	   $isValid = true;
	   $atIndex = strrpos($email, "@");
	   if (is_bool($atIndex) && !$atIndex)
	   { $isValid = false; }
	   else
	   {
		  $domain = substr($email, $atIndex+1);
		  $local = substr($email, 0, $atIndex);
		  $localLen = strlen($local);
		  $domainLen = strlen($domain);
		  if ($localLen < 1 || $localLen > 64)
		  { $isValid = false; }
		  else if ($domainLen < 1 || $domainLen > 255)
		  { $isValid = false; }
		  else if ($local[0] == '.' || $local[$localLen-1] == '.')
		  { $isValid = false; }
		  else if (preg_match('/\\.\\./', $local))
		  { $isValid = false; }
		  else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
		  { $isValid = false;  }
		  else if (preg_match('/\\.\\./', $domain))
		  { $isValid = false; }
		  else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
		  {
			 // character not valid in local part unless 
			 // local part is quoted
			 if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local)))
			 { $isValid = false; }
		  }
		  /*
		  if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
		  {
			 // domain not found in DNS
			 $isValid = false;
		  }
		  */
	   }
	   return $isValid;
	}

	function strip_html($text = "")
	{
		if( (!$text) or (empty($text)) )
		{ return ""; }
		$outside = true;
		$rawText = "";
		$length = strlen($text);
		$count = 0;
		for($count=0; $count < $length; $count++)
		{
			$digit = substr($text,$count,1);
			if(!empty($digit))
			{
				if( ($outside) and ($digit != "<") and ($digit != ">") ) { $rawText .= $digit; }
				if($digit == "<") { $outside = false; }
				if($digit == ">") { $outside = true; }
			}
		}
		return $rawText;
	}
	
	function escape($string) 
	{
		if(get_magic_quotes_gpc()) $string = stripslashes($string);
		return mysql_real_escape_string($string);
	}
	
	function dbVal($val, $type)
	{
		switch ($type)
		{
			case 'int':
				if(is_numeric($val))
				{ return $val; }
				else
				{ return 0; }
			case 'txt':
				return '"'.$val.'"';
		}
	}
	
	function getListCommandsPanel($set_l='', $set_r='', $buttons_l='', $buttons_r='', $dates=array())
	{
		//if(!defined('AJAX_RUN'))
		//{
			if(($set_l != '') || ($set_r != '') || ($buttons_l != '') || ($buttons_r != ''))
			{
				$out  = '<div id="commands" class="ui-corner-tl ui-corner-tr">';
				
				$out .= '<div id="commands_left" style="float:left;';
				if(($set_r) || ($buttons_r))
				{ $out .= ' width:50%;">'; }
				else
				{ $out .= ' width:90%;">'; }
				if($set_l)
				{ $out .= self::getCommandButtons('', $set_l); }
				if($buttons_l)
				{ $out .= self::getCommandButtons($buttons_l); }
				$out .= '</div>';
				if(($set_r) || ($buttons_r))
				{ $out .= '<div id="commands_right" style="width:10%; float:left; text-align:right;">'; }
				else
				{ $out .= '<div id="commands_right" style="width:50%; float:left; text-align:right;">'; }
				if($set_r)
				{ $out .= self::getCommandButtons('', $set_r); }
				if($buttons_r)
				{ $out .= self::getCommandButtons($buttons_r); }
				$out .= '</div><div class="clear"></div>';
				$out .= '</div><div class="clear"></div>';
				return $out;
			}
		//}
	}
	
	function getCommandButtons($buttons, $set='', $button='')
	{
		$out = '';
		global $txt;
		global $ac;
		
		if(!($buttons) && ($set != ''))
		{ $buttons = self::getCommandButtonsSet($set); }
		if($buttons)
		{
			foreach($buttons as $button)
			{ 
				switch($button['type'])
				{
					case 'sqlpager':
						$out .= '<div class="sqlpager cmbset-input">
								<a id="page_first" href="#"><img class="first command" src="'.KATANA_IMAGES_URL.'pager/first.png"></a>
								<a id="page_prev" href="#"><img class="prev command" src="'.KATANA_IMAGES_URL.'pager/prev.png"></a>';

						$out .= '&nbsp;<input disabled="disabled" name="page" id="page" type="text" class="xx-small" value="'.$ac->Pager->getPageCurrent().'">&nbsp;';
						$out .= '/&nbsp;<input disabled="disabled" id="pages-count" type="text" class="xx-small" value="">&nbsp;';
						
						$out .= '<a id="page_next" href="#"><img class="next command" src="'.KATANA_IMAGES_URL.'pager/next.png"></a>
								<a id="page_last" href="#"><img class="last command" src="'.KATANA_IMAGES_URL.'pager/last.png"></a>
							</div>';
						break;
					case 'sqlfilter':
						$out .= '<div class="filter cmbset-input">
									'.ucfirst($txt->getWord('search')).': <input name="q" clas="small" name="filter" id="sqlfilter" value="'.$_REQUEST['q'].'" maxlength="20" size="20" type="text">
								</div>';
						break;
					case 'pager':
						$out .= '<div class="pager cmbset-input">
								<img class="first" src="'.KATANA_IMAGES_URL.'pager/first.png">
								<img class="prev" src="'.KATANA_IMAGES_URL.'pager/prev.png">
								<input type="text" class="pagedisplay" value="'.intval($_REQUEST['page']).'">
								<img class="next" src="'.KATANA_IMAGES_URL.'pager/next.png">
								<img class="last" src="'.KATANA_IMAGES_URL.'pager/last.png">
								<select name="pager" class="pagesize">
									<option value="40"  '.$txt->getIsSelectedHTML($_REQUEST['pager'], 40).'>40</option>
									<option value="80" '.$txt->getIsSelectedHTML($_REQUEST['pager'], 80).'>80</option>
									<option value="120" '.$txt->getIsSelectedHTML($_REQUEST['pager'], 120).'>120</option>
									<option value="160" '.$txt->getIsSelectedHTML($_REQUEST['pager'], 160).'>160</option>
								</select>
							</div>';
						break;
					case 'filter':
						$out .= '<div class="filter cmbset-input">
									'.ucfirst($txt->getWord('search')).': <input clas="small" name="filter" id="filter-box" value="" maxlength="20" size="20" type="text">
									<input id="filter-clear-button" type="submit" value="Clear"/>
								</div>';
						break;
					case 'period':
						$out .= '<div class="period cmbset-input">'.ucfirst($txt->getWord('date')).':&nbsp;';
						$out .= 	'<select class="period-select" name="period" onchange="setPeriod(true);">';
				$out .= 		'<option value="today" '.$txt->getIsSelectedHTML($_REQUEST['period'], 'today').'>'.ucfirst($txt->getWord('today')).'</option>';
				//$out .= 		'<option value="this_week" '.$txt->getIsSelectedHTML($_REQUEST['period'], 'this_week').'>'.ucfirst($txt->getWord('this_week')).'</option>';
				$out .= 		'<option value="this_month" '.$txt->getIsSelectedHTML($_REQUEST['period'], 'this_month', true).'>'.ucfirst($txt->getWord('this_month')).'</option>';
				$out .= 		'<option value="this_year" '.$txt->getIsSelectedHTML($_REQUEST['period'], 'this_year').'>'.ucfirst($txt->getWord('this_year')).'</option>';
				$out .= 		'<option value="custom" '.$txt->getIsSelectedHTML($_REQUEST['period'], 'custom', true).'>'.ucfirst($txt->getWord('choose_date')).'...</option>';
						$out .= 	'</select>&nbsp;&nbsp;';
						$out .= 	ucfirst($txt->getWord('start_date')).':&nbsp;';
						$out .= 	'<input type="text" name="date_start" class="period_filter_date_start xsmall-s" value="'.$_REQUEST['date_start'].'" />&nbsp;&nbsp;';
						$out .= 	ucfirst($txt->getWord('end_date')).':&nbsp;';
						$out .= 	'<input type="text" name="date_end" class="period_filter_date_end xsmall-s" value="'.$_REQUEST['date_end'].'" />&nbsp;&nbsp;';
						$out .= '</div>';
						break;
						
					case 'shipping_methods':
						
						global $shop;
						if(is_object($shop))
						{
							if($shop->getShopShippingMethods())
							{
								$out .= '<div class="shipping_methods cmbset-input">';//.ucfirst($txt->getWord('shipping_method')).':&nbsp;';
								$out .= 	'<select class="shipping_methods-select medium" name="shipping-method" onchange="submit();">';
								$out .= '<option value="0" '.$txt->getIsSelectedHTML($_REQUEST['shipping-method'], '', true).'>'.ucfirst($txt->getWord('shipping_method')).'</option>';
								foreach($shop->getShopShippingMethods() as $method)
								{ $out .= '<option value="'.$method['id'].'" '.$txt->getIsSelectedHTML($_REQUEST['shipping-method'], $method['id']).'>'.$method['title'].'</option>'; }
								$out .= 	'</select>&nbsp;&nbsp;';
								$out .= '</div>';
							}
						}
						break;
					
					case 'ad_types':
						global $adc;
						if(is_object($adc))
						{
							if($adc->getAdTypes())
							{
								$out .= '<div class="ad_types cmbset-input">';
								$out .= 	'<select class="ad_types-select small" name="typeId" id="typeId" onchange="loadItems();">';
								$out .= '<option value="0" '.$txt->getIsSelectedHTML($_REQUEST['typeId'], '', true).'>'.ucfirst($txt->getWord('all').' '.$txt->getWord('ad_types')).'</option>';
								foreach($adc->getAdTypes() as $type)
								{ $out .= '<option value="'.$type->getId().'" '.$txt->getIsSelectedHTML($_REQUEST['typeId'], $type->getId()).'>'.$type->getTitle().'</option>'; }
								$out .= 	'</select>&nbsp;&nbsp;';
								$out .= '</div>';
							}
						}
						break;
						
					case 'ad_cats':
						global $adc;
						if(is_object($adc))
						{
							if($adc->getAdCats())
							{
								$out .= '<div class="ad_cats cmbset-input">';
								$out .= 	'<select class="ad_types-select small" name="catId" id="catId" onchange="loadItems();">';
								$out .= '<option value="0" '.$txt->getIsSelectedHTML($_REQUEST['catId'], '', true).'>'.ucfirst($txt->getWord('all').' '.$txt->getWord('categories')).'</option>';
								foreach($adc->getAdCats() as $cat)
								{ $out .= '<option value="'.$cat->getId().'" '.$txt->getIsSelectedHTML($_REQUEST['catId'], $cat->getId()).'>'.$cat->getTitle().'</option>'; }
								$out .= 	'</select>&nbsp;&nbsp;';
								$out .= '</div>';
							}
						}
						break;
					
					case 'ad_brands':
						global $adc;
						if(is_object($adc))
						{
							$adc->setFrontend(1);
							if($adc->getAdBrands())
							{
								$out .= '<div class="ad_brands cmbset-input">';
								$out .= 	'<select class="ad_types-select small" name="brandId" id="brandId" onchange="loadItems();">';
								$out .= '<option value="0" '.$txt->getIsSelectedHTML($_REQUEST['brandId'], '', true).'>'.ucfirst($txt->getWord('all').' '.$txt->getWord('brands')).'</option>';
								foreach($adc->getAdBrands() as $brand)
								{ $out .= '<option value="'.$brand->getId().'" '.$txt->getIsSelectedHTML($_REQUEST['brandId'], $brand->getId()).'>'.$brand->getTitle().'</option>'; }
								$out .= 	'</select>&nbsp;&nbsp;';
								$out .= '</div>';
							}
							$adc->setFrontend(0);
						}
						break;
						
					default:
						if($button['href'] != '')
						{ $out .= '<a href="'.$button['href'].'">'; }
						$out .= '<img class="icon command" src="'.SYSICONS_URL.$button['image'].'"';
						if($button['id'])
						{ $out .= ' id="'.$button['id'].'"'; }
						if($button['onclick'])
						{ $out .= ' onclick="'.$button['onclick'].'"'; }
						if($button['onmousedown'])
						{ $out .= ' onmousedown="'.$button['onmousedown'].'"'; }
						if($button['onmouseup'])
						{ $out .= ' onmouseup="'.$button['onmouseup'].'"'; }
						if($button['onmouseover'])
						{ $out .= ' onmouseover="'.$button['onmouseover'].'"'; }
						if($button['onmouseout'])
						{ $out .= ' onmouseout="'.$button['onmouseout'].'"'; }
						$out .= ' title="'.$button['title'].'" />';
						if($button['href'] != '')
						{ $out .= '</a>'; }
						$out .= '&nbsp;';
				}
			}
		}
		return $out;
	}
	
	function getCommandButton($button, $elementId)
	{
		if($button && $elementId)
		{
			switch ($button)
			{
				case 'up':
					$buttons[0]['image'] = "arrow_up_16.gif";
					$buttons[0]['onmousedown'] = "document.getElementById('up').value='".$elementId."'";
					$buttons[0]['onmouseup'] = "edit_form.submit();";
					$buttons[0]['title'] = ucfirst($this->Words['move_up']);
					break;
				case 'down':
					$buttons[0]['image'] = "arrow_down_16.gif";
					$buttons[0]['onmousedown'] = "document.getElementById('down').value='".$elementId."'";
					$buttons[0]['onmouseup'] = "edit_form.submit();";
					$buttons[0]['title'] = ucfirst($this->Words['move_down']);
					break;
			}
			if($buttons)
			{ return self::getCommandButtons($buttons); }
		}
	}
	
	function getVisibleFieldsObject($object)
	{
		if(is_object($object))
		{
			$visible = 0;
			if($object->getVisible())
			{ $visible = 1; }
			
			$output = '<img style="cursor:pointer;"';
			$output .= ' src="'.SYSICONS_URL.'visible_'.$visible.'_16.gif"';
			if($visible == 0)
			{ $output .= ' title="'.ucfirst($this->Words['visible']).'" onmousedown="document.getElementById(\'visible\').value='.$object->getId().';"'; }
			else
			{ $output .= ' title="'.ucfirst($this->Words['invisible']).'" onmousedown="document.getElementById(\'invisible\').value='.$object->getId().';"'; }
			$output .= ' onmouseup="edit_form.submit();" />';
			return $output;
		}
	}

	function loadUserLevels()
	{
		$result = mysql_query('SELECT id, level FROM '.DB_PERFIX.'user_levels ORDER BY id;');
		while($row = mysql_fetch_array($result))
		{
			$this->UserLevels[$row['id']]['id'] = $row['id'];
			$this->UserLevels[$row['id']]['level'] = $row['level'];
		}
	}
	
	function getCommandButtonsSet($set)
	{
		if($set)
		{
			$selectors = explode('-',$set);
			if(count($selectors))
			{
				$i = 0;
				foreach($selectors as $selector)
				{
					$buttons[$i]['type'] = 'button';
					switch ($selector)
					{
						case 'n':
							$buttons[$i]['image'] = "add_16.gif";
							$buttons[$i]['onclick'] = "addNewDialog();";
							$buttons[$i]['title'] = ucfirst(self::getWord('add').' '.self::getWord('new'));
							break;
						case 's':
							$buttons[$i]['image'] = "filesave_16.gif";
							$buttons[$i]['onclick'] = "edit_form.submit();";
							$buttons[$i]['title'] = ucfirst(self::getWord('save'));
							break;
						case 'sa':
							$buttons[$i]['image'] = "save_all_16.gif";
							$buttons[$i]['onclick'] = "edit_form.submit();";
							$buttons[$i]['title'] = ucfirst(self::getWord('save').' '.self::getWord('all'));
							break;
						case 'jqGridSave':
							$buttons[$i]['image'] = "save_all_16.gif";
							$buttons[$i]['onclick'] = "edit_form.submit();";
							$buttons[$i]['title'] = ucfirst(self::getWord('save').' '.self::getWord('all'));
							break;
						case 'reload':
							$buttons[$i]['image'] = "reload_16.png";
							$buttons[$i]['onclick'] = "edit_form.submit();";
							$buttons[$i]['title'] = ucfirst(self::getWord('reload'));
							break;
						case 'a':
							$buttons[$i]['image'] = "active_1_16.gif";
							$buttons[$i]['onclick'] = "edit_form.submit();";
							$buttons[$i]['onmousedown'] = "document.getElementById('activate').value=-1;";
							$buttons[$i]['title'] = ucfirst(self::getWord('activate').' '.self::getWord('selected_elements'));
							break;
						case 'd':
							$buttons[$i]['image'] = "active_0_16.gif";
							$buttons[$i]['onclick'] = "edit_form.submit();";
							$buttons[$i]['onmousedown'] = "document.getElementById('deactivate').value=-1;";
							$buttons[$i]['title'] = ucfirst(self::getWord('deactivate').' '.self::getWord('selected_elements'));
							break;
						case 'del':
							$buttons[$i]['image'] = "delete_16.gif";
							$buttons[$i]['onclick'] = "edit_form.submit();";
							$buttons[$i]['onmousedown'] = "document.getElementById('delete').value=-1;";
							$buttons[$i]['title'] = ucfirst(self::getWord('delete').' '.self::getWord('selected_elements'));
							break;
						case 'sqlpager':
							$buttons[$i]['type'] = 'sqlpager';
							break;
						case 'sqlfilter':
							$buttons[$i]['type'] = 'sqlfilter';
							break;
						case 'pager':
							$buttons[$i]['type'] = 'pager';
							break;
						case 'filter':
							$buttons[$i]['type'] = 'filter';
							break;
						case 'period':
							$buttons[$i]['type'] = 'period';
							break;
						case 'shipping_methods':
							$buttons[$i]['type'] = 'shipping_methods';
							break;	
						case 'ad_types':
							$buttons[$i]['type'] = 'ad_types';
							break;
						case 'ad_cats':
							$buttons[$i]['type'] = 'ad_cats';
							break;
						case 'ad_brands':
							$buttons[$i]['type'] = 'ad_brands';
							break;
					}
					$i++;
				}
			}
		}
		return $buttons;
	}
	
	function getComponentForm($top=1, $bot=0)
	{
		$out = '';
		if($top > 0)
		{ $out = '<form id="edit_form" name="edit_form" action="'.self::getFormAction().'" method="post" enctype="multipart/form-data">'; }
		if($bot > 0)
		{ $out = '</form>'; }
		return $out;
	}
	
	function getComponentContent($left=1, $right=0, $top=1, $bot=0)
	{
		$out = '';
		if($left > 0)
		{ 
			if($top > 0)
			{ $out = '<table cellpadding="0" cellspacing="0" border="0" class="main_win"><tbody><tr><td class="win_left">'; }
			if($bot > 0)
			{ $out = '</td>'; }
		}
		if($right > 0)
		{
			if($top > 0)
			{ $out = '<td class="win_right">'; }
			if($bot > 0)
			{ $out = '</td></tr></tbody></table>'; }
		}
		return $out;
	}
	
	function getComponentListLoading()
	{
		$out  = '<tr class="items loading">';
		$out .=		'<td class="first center">0</td>';
		$out .=		'<td class="center"><input type="checkbox" name="selectx" value="" /></td>';
		$out .=		'<td><img src="'.SYSICONS_URL.'loading_16.gif" />&nbsp;&nbsp;Loading...</td>';
		$out .=	'</tr>';
		return $out;
	}
}

?>